﻿#region using statements

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

using NGen;
using NGen.Managers.GUI;
using NGen.Managers.GameState;
using NGen.Managers.Input;
using NGen.Managers.Particle;

using Nuclex.Input;

using XNAGameDemo.GUI;
using XNAGameDemo.Particles;

#endregion

namespace XNAGameDemo.GameStates
{
	public class GameStateIntro : GameState, IKeyboardListener, IMouseListener
	{
		private readonly GUIElement m_gui = new GUIElementIntroState();

		private static GUIElementStateSwitch m_guiStateSwitch;

		private ExampleParticleSystem m_particle;

		#region IKeyboardListener Members

		public void KeyPressed(Keys p_key) {}

		public void KeyReleased(Keys p_key) {}

		#endregion

		#region IMouseListener Members

		public void MouseMoved(float p_x, float p_y) {
			var pos = m_particle.EmitterLocation;
			pos.X = p_x;
			pos.Y = p_y;
			m_particle.EmitterLocation = pos;
		}

		public void MousePressed(MouseButtons p_button) {}

		public void MouseReleased(MouseButtons p_button) {}

		public void MouseWheelScroll(float p_ticks) {}

		#endregion

		protected override void _Initialize() {
			GameEngine.GetService<IManagerInput>().AddKeyboardListener(this);
			GameEngine.GetService<IManagerInput>().AddMouseListener(this);
			if(m_guiStateSwitch == null) {
				m_guiStateSwitch = new GUIElementStateSwitch();
				GameEngine.GetService<IManagerGUI>().AddElement(m_guiStateSwitch);
			}
			GameEngine.GetService<IManagerGUI>().AddElement(m_gui);
			m_particle = new ExampleParticleSystem(Vector2.Zero);
			GameEngine.GetService<IManagerParticles>().AddParticleSystem(m_particle);
		}

		protected override void _Cleanup() {
			GameEngine.GetService<IManagerInput>().RemoveKeyboardListener(this);
			GameEngine.GetService<IManagerInput>().RemoveMouseListener(this);
			GameEngine.GetService<IManagerGUI>().RemoveElement(m_gui);
			GameEngine.GetService<IManagerParticles>().DestroyParticleSystem(m_particle);
		}

		protected override void _OnFocusLost() {
			
		}

		protected override void _OnFocusGained() {}

		protected override void _Update(GameTime p_gameTime) {
		}

		protected override void _Draw(GameTime p_gameTime) {			
			GameEngine.GraphicsDeviceManager.GraphicsDevice.Clear(Color.Red);
		}
	}
}